import * as echart from 'echarts'

import chinaMapData from '../data/china.json'

//注册地图组件
echart.registerMap('china', chinaMapData)

export default function (el: HTMLElement) {
  const echartsInstance = echart.init(el, 'light', {
    renderer: 'svg'
  })
  const setOptions = (options: echarts.EChartsOption) => {
    echartsInstance.setOption(options)
  }
  const updateSize = () => {
    echartsInstance.resize()
  }
  //使用屏幕缩放扩大时进行重绘
  window.addEventListener('resize', () => {
    updateSize()
  })

  return {
    echartsInstance,
    setOptions,
    updateSize
  }
}
